package org.jetlinks.pro.device.service.data;

import lombok.Getter;
import lombok.Setter;
import org.jetlinks.pro.utils.MessageTypeMatcher;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@ConfigurationProperties(prefix = "jetlinks.device.storage")
@Getter
@Setter
public class DeviceDataStorageProperties {

    //默认数据存储策略,每个属性为一行数据
    private String defaultPolicy = "default-row";

    //是否保存最新数据到数据库
    private boolean enableLastDataInDb = false;

    private Log log = new Log();

    private Event event = new Event();

    @Getter
    @Setter
    public static class Log extends MessageTypeMatcher {

    }

    @Getter
    @Setter
    public static class Event {
        public static final Event DEFAULT = new Event();

        //使用JSON字符来存储事件数据
        private boolean usingJsonString;
        //相同产品的设备数据使用同一个表来存储
        private boolean eventAllInOne;

        //忽略未定义物模型的事件
        private boolean ignoreUndefined = true;

        public boolean eventIsAllInOne() {
            return usingJsonString && eventAllInOne;
        }

        public boolean canIgnoreUndefined() {
            return ignoreUndefined || !eventIsAllInOne();
        }
    }

}
